package lcr;

public class Test0049 {
}

class Solution0049_1 {
    public int ans = 0;
    public int sumNumbers(TreeNode root) {
        dfs(root,0);
        return ans;
    }

    public void dfs(TreeNode node, int sum){
        if (node==null) return;
        sum = sum*10+node.val;
        if (node.left==null&&node.right==null){
            ans += sum;
        }
        else {
            dfs(node.left,sum);
            dfs(node.right,sum);
        }
    }
}
